
// TypeScript file
/**
 * 首页
 * @AUTHOR:JT
 * @TIME:201703011547
 */

class IndexUI extends egret.Sprite {
	public constructor() {
		super();
		this.once(egret.Event.ADDED_TO_STAGE, this.createView, this);
	}
	private createView(): void {

		//index容器
		var word = diva(0x000000, 0, 0, 0, 640, 0, 640, 1136, 0, 1136, 0, 1136, 0, 0);//添加容器
		this.addChild(word);
		 var indexBG = createBitmap("swin_bg_png")
        word.addChild(indexBG);
		//波纹背景【在index容器中】
		var ripple1 = createBitmap("bg_ripple_png", 0, 0);
		var ripple2 = createBitmap("bg_ripple_png", 630, 0);
		word.addChild(ripple1);
		word.addChild(ripple2);
		egret.Tween.get(ripple1, { loop: true }).to({ x: -630 }, 30000);
		egret.Tween.get(ripple2, { loop: true }).to({ x: 0 }, 30000);

		// 首页logo的文字图片	
		var word_logo_word = createBitmap("logo_word_png", 382, -80);
		egret.Tween.get(word_logo_word).to({ x: 360, y: 45 }, 200).to({ x: 400, y: 30 }, 300).to({ x: 390, y: 50 }, 200).to({ x: 388, y: 50 }, 300).to({ x: 385, y: 45 }, 200);
		word.addChild(word_logo_word);

		// 首页logo的图标
		var word_logo_icon = createBitmap("logo_icon_png", 550, 45, "", 23, 23, 360);
		word.addChild(word_logo_icon);
		egret.Tween.get(word_logo_icon, { loop: true }).to({ scaleX: 1.3, scaleY: 1.3 }, 1000).to({ scaleX: 1, scaleY: 1 }, 1000);;

		// 首页人物字图	
		var word_people = createBitmap("word_people_png", -630, 130);
		egret.Tween.get(word_people).to({ x: 0 }, 300);
		word.addChild(word_people);

		// 首页奥运字图	
		var word_aoyun = createBitmap("word_aoyun_png", 666, 45);
		egret.Tween.get(word_aoyun).to({ x: 37 }, 500);
		word.addChild(word_aoyun);
		// 首页指尖字图	
		var word_zhijian = createBitmap("word_zhijian_png", 666, 225);
		egret.Tween.get(word_zhijian).to({ x: 37 }, 800);
		word.addChild(word_zhijian);
		// 首页自由泳字图	
		var word_ziyouyong = createBitmap("word_ziyouyong_png", 666, 342);
		egret.Tween.get(word_ziyouyong).to({ x: 37 }, 1100);
		word.addChild(word_ziyouyong);

		// 开始按钮	
		var word_play = createBitmap("word_play_png", 166, 1135, );
		egret.Tween.get(word_play).to({ y: 1135 }, 500).to({ y: 871 }, 500);
		word.addChild(word_play);
		word_play.touchEnabled = true;
		if (word_play.touchEnabled = true) {
			word_play.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
				word_play.touchEnabled = false;
				SenceManage.create(this.stage).loadSence("preload", null, swinUI);
				egret.Tween.get(this).to({ x: -1280 }, 1000);
				egret.Tween.get(word_play).to({y:880},300).to({y:871},300);
			}, this)
		}

		//展开规则音效
		var soundopen = new egret.Sound();
		soundopen.load("resource/assets/zhankaisheng.mp3");
		// 游戏规则提示文
		var game_Rule = createTextFiled("游戏规则", 245, 1018, 30, 0XFFFFFF, "center", 150, 30);
		game_Rule.bold = true;
		game_Rule.touchEnabled = true;
		egret.Tween.get(game_Rule).to({ alpha: 0 }, 100).to({ alpha: 0 }, 900).to({ alpha: 1 }, 300);
		game_Rule.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
			game_Rule.touchEnabled = false;
			word_play.touchEnabled = false;
			egret.Tween.get(rule).to({ scaleX: 1, scaleY: 1 }, 300);
			egret.Tween.get(rule).to({ scaleX: 1, scaleY: 1 }, 300);
			egret.Tween.get(game_Rule).to({ textColor: 0xff0000, y: 1030 }, 200).to({ textColor: 0xffffff, y: 1018 }, 150);
			soundopen.play(0,1);
		}, this)
		word.addChild(game_Rule);

		// 游戏规则遮罩容器
		var rule = diva(0x262626, 0.7, 62, 58, 578, 58, 578, 1066, 62, 1066, 62, 58, 540, 98);           //添加容器
		rule.scaleX = 0;
		rule.scaleY = 0;
		rule.anchorOffsetX = 540;
		rule.anchorOffsetY = 98;
		// 
		rule.touchEnabled = true;
		rule.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
			egret.Tween.get(rule_close).to({ scaleX: 0.5, scaleY: 0.5, rotation: 360 }, 300).to({ scaleX: 1, scaleY: 1, rotation: 720 }, 400);
			egret.Tween.get(rule).to({ scaleX: 0, scaleY: 0 }, 300);
			game_Rule.touchEnabled = true;
			word_play.touchEnabled = true;
			closesound.play(1,1)
		}, this)
		// 
		word.addChild(rule);

		//游戏规则遮罩关闭按钮
		var closesound = new egret.Sound()
		closesound.load("resource/assets/xiuxiuxiu.mp3");
		var rule_close = createBitmap("rule_close_png", 530, 86);
		rule_close.x = rule_close.x + rule_close.width * .5;
		rule_close.y = rule_close.y + rule_close.height * .5;
		rule_close.anchorOffsetX = rule_close.width * .5;
		rule_close.anchorOffsetY = rule_close.height * .5;
		rule.addChild(rule_close);

		//游戏规则标题
		var rule_ruleTitle = createTextFiled("游戏规则", 0, 134, 30, 0XFFFFFF, "center", 640, 42);
		rule_ruleTitle.bold = true;
		rule.addChild(rule_ruleTitle);
		
		//规则1和2
		var rule_ruleText = createTextFiled("1.每玩一次游戏可获得一次抽奖机会；\n\n\n2.游戏排名越靠前，中奖几率越大。", 104, 236, 24, 0xffffff, "left");
		rule_ruleText.bold = true;
		rule.addChild(rule_ruleText);

		//奖品设置标题
		var rule_prizeSetting = createTextFiled("奖品设置", 0, 420, 30, 0XFFFFFF, "center", 640, 30);
		rule_prizeSetting.bold = true;
		rule.addChild(rule_prizeSetting);

		//奖品设置1到7
		var rule_prizeSettingText = createTextFiled("1.小米运动手环\n\n2.超轻户外背包\n\n3.乐扣便携运动水壶\n\n4.迪卡侬透气速干T恤\n\n5.迪卡侬速干毛巾\n\n6.多功能运动腰包\n\n7.安联运动意外保障计划（7天）", 104, 528, 24, 0xffffff, "left");
		rule_prizeSettingText.bold = true;
		rule.addChild(rule_prizeSettingText);
	}
}